/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainDetailPanel.java
 *
 * Created on 29/12/2010, 14:19:12
 */
package net.stuffrepos.bricknetcenter.gui.inventories;

import net.stuffrepos.bricknetcenter.database.DataEvent;
import net.stuffrepos.bricknetcenter.database.DataListener;
import net.stuffrepos.bricknetcenter.database.DataManager;
import net.stuffrepos.bricknetcenter.gui.FormatHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class MainDetailPanel extends javax.swing.JPanel {

    private static final Log log = LogFactory.getLog(MainDetailPanel.class);

    /** Creates new form MainDetailPanel */
    public MainDetailPanel() {
        initComponents();
        FormatHelper.formatTitleLabel(title);

        refreshInventoriesCount();

        DataManager.getInstance().addDataListener(new DataListener() {

            @Override
            public void dataChanged(DataEvent event) {
                refreshInventoriesCount();
            }
        });
    }

    public void refreshInventoriesCount() {
        try {
            inventoriesCount.setText(
                    Integer.toString(DataManager.getInstance().getInventoriesCount()));

        } catch (Exception ex) {
            log.warn("", ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        title = new javax.swing.JLabel();
        inventoriesCountLabel = new javax.swing.JLabel();
        inventoriesCount = new javax.swing.JLabel();

        title.setText("Inventories");

        inventoriesCountLabel.setLabelFor(inventoriesCount);
        inventoriesCountLabel.setText("Total");

        inventoriesCount.setText("0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(title)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(inventoriesCountLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inventoriesCount)))
                .addContainerGap(318, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(title)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inventoriesCountLabel)
                    .addComponent(inventoriesCount))
                .addContainerGap(248, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel inventoriesCount;
    private javax.swing.JLabel inventoriesCountLabel;
    private javax.swing.JLabel title;
    // End of variables declaration//GEN-END:variables
}
